package com.example.springboot_study.jpa;

import com.example.springboot_study.entity.primary.User;
import com.example.springboot_study.jpa.primary.TestRepository;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author : liqun
 * @createTime : 2021/9/21 13:46
 */
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class JpaTest2 {
    @Autowired
    private TestRepository testRepository;

    @Test
    @Transactional(value="transactionManagerPrimary",isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED)
    public void test() throws Exception {

        // 创建10条记录
        testRepository.save(new User("AAA", 10));
        testRepository.save(new User("BBB", 20));
        testRepository.save(new User("CCC", 30));
        testRepository.save(new User("DDD", 40));
        testRepository.save(new User("EEE", 50));
        testRepository.save(new User("FFF", 60));
        testRepository.save(new User("GGG", 70));
        testRepository.save(new User("HHH", 80));
        testRepository.save(new User("III", 90));
        testRepository.save(new User("JJJ", 100));

        // 省略后续的一些验证操作
    }
}
